package com.efast.dmom.mes.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.efast.dmom.mes.entity.base.BaseEntity;

/**
 * @author Aaron Liu
 *
 * @date:2020年1月13日
 */
abstract class BeanListSupport<T extends BaseEntity> implements Serializable {

	private static final long serialVersionUID = 7673119153766144383L;

	protected List<T> entityList = null;

	protected BaseEntity owner;

	protected BeanListSupport(BaseEntity owner, List<T> entityList) {
		this.owner = owner;
		this.entityList = entityList;
	}

	protected List<T> getAllEntity() {
		return entityList;
	}

	protected final Object getBean(String name) {

		if (this.entityList != null && name != null) {

			for (int i = 0; i < entityList.size(); i++) {

				BaseEntity temp = entityList.get(i);

				//if (name.equals(temp.getName())) {
				if (name.equals("")) {
					return temp;
				}
			}
		}
		return null;
	}

	protected boolean addEntity(T beanObj) {

		if (beanObj != null) {

			if (entityList == null) {
				entityList = new ArrayList<T>();
			}

			if (!entityList.contains(beanObj)) {
				entityList.add(beanObj);
				return true;
			}
		}
		return false;
	}

	protected boolean removeEntity(T entity) {

		if (entity != null && entityList.contains(entity)) {

			return entityList.remove(entity);
		}

		return false;
	}

	protected boolean removeBean(T beanObj) {

		if (beanObj != null) {
			return entityList.remove(beanObj);
		}

		return false;
	}
}
